package com.coconet.gas.rest;

import com.coconet.gas.constant.dwEnum;
import com.coconet.gas.dao.ScanQuartzMapper;
import com.coconet.gas.quartz.ScanQuartzJob;
import com.coconet.gas.vo.dw.ScanQuartz;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import response.BaseResponse;
import response.ObjectRestResponse;

import java.util.List;

@RestController
@RequestMapping("scanQuartz")
public class ScanQuartzRest {
    @Autowired
    private ScanQuartzJob sqJob;
    @Autowired
    private ScanQuartzMapper sqMapper;

    @ApiOperation(value = "开始定时扫描", httpMethod = "POST")
    @PostMapping(value = "/startScanQuartz")
    public BaseResponse startSysMysqlBackUP(@RequestBody List<ScanQuartz> sqList) {
        for (ScanQuartz sq : sqList) {
            sqJob.run(sq);
        }
        return new BaseResponse(dwEnum.SUCCEESS.code(), "成功");

    }

    @ApiOperation(value = "停止定时扫描", httpMethod = "POST")
    @PostMapping(value = "/stopScanQuartz")
    public BaseResponse stopSysMysqlBackUP(@RequestBody List<String> taskIdList) {
        for (String taskId : taskIdList) {
            sqJob.stop(taskId);
        }
        return new BaseResponse(dwEnum.SUCCEESS.code(), "成功");

    }

    @ApiOperation(value = "更改定时扫描周期", httpMethod = "POST")
    @PostMapping(value = "/updateScanQuartz")
    public BaseResponse updateSysMysqlBackUP(@RequestBody ScanQuartz sq) {
        sqJob.update(sq);
        return new BaseResponse(dwEnum.SUCCEESS.code(), "成功");

    }

    @ApiOperation(value = "查询corn表达式", httpMethod = "GET")
    @GetMapping(value = "/getCorn/{taskId}")
    public ObjectRestResponse getLogCorn(@PathVariable String taskId){
        ScanQuartz sq = sqMapper.selectByPrimaryKey(taskId);
        return new ObjectRestResponse(dwEnum.SUCCEESS.code(),"...",sq.getCron());
    }
}